home *** CD-ROM | disk | FTP | other *** search
/ HPAVC / HPAVC CD-ROM.iso / pc / ML_BME1.ZIP / PLASMA / GENP2.CPP < prev    next >
Encoding:
C/C++ Source or Header  |  1996-12-21  |  1.9 KB  |  78 lines

  1. // *************************************************************************
  2. //  Plasma cloud generator
  3. //  by Maple Leaf, Dec 1996
  4. //  -----------------------------------------------------------------------
  5. //  No rights reserved
  6. // *************************************************************************
  7.  
  8. #include <stdio.h>
  9. #include <stdlib.h>
  10. #include <math.h>
  11.  
  12. void    main()
  13. {
  14.     float    x,y,count,i;
  15.     int    lead,offset;
  16.     FILE    *fp;
  17.     unsigned char value;
  18.  
  19.     printf("\nPlasma generator, by Maple Leaf, 1996\n\nProcessing ...!\n");
  20.  
  21.     if (!(fp=fopen("PLASMA.DAT","wb")))
  22.     {
  23.         printf("\7Cant open output file PLASMA.DAT\n");
  24.         exit(255);
  25.     }
  26.  
  27.     /* First generate the plasma map.  This is effectively just an
  28.        arbitrary function of x and y which gives a smooth but
  29.        non-uniform surface */
  30.  
  31.     printf("\nGenerating plasma cloud ");
  32.  
  33.     for (y=0;y<300;y++) {
  34.       for (x=0;x<512;x++)
  35.       {
  36.         value=64+  10*(sin(x/20) + sin(x*y/2000) +
  37.                   sin((x+y)/100) + sin((y-x)/70) +
  38.                   sin((x+4*y)/70) +
  39.                   sin(hypot(256-x,150-y/8)/30)
  40.                   );
  41.         fputc(value,fp);
  42.       }
  43.       if ((int)y % 30 == 0) printf(".");
  44.     }
  45.  
  46.     printf("\nGenerating movement path ...");
  47.     /* Then arbitrary movement for two pointers */
  48.  
  49.     for (count=0;count<10000;count++)
  50.     {
  51.         lead=           96+92*cos(count/32)
  52.              +512*(int)(48+47*sin(count/16));
  53.         offset=         96+92*sin(count/21)
  54.              +512*(int)(48+47*cos(count/24))
  55.              -lead;
  56.         fwrite(&lead,2,1,fp);
  57.         fwrite(&offset,2,1,fp);
  58.     }
  59.  
  60.     printf("\nGenerating palette ...\n");
  61.     /* And a smooth transition colour lookup table */
  62.  
  63.     for (i=-256; i<256*39; i++)
  64.         if (i<0)
  65.         {
  66.             fputc(0,fp);
  67.             fputc(0,fp);
  68.             fputc(0,fp);
  69.         }
  70.         else
  71.         {
  72.             fputc((sin(i/200)*cos(i/32)*31+31),fp);
  73.             fputc((sin(i/100)*sin(3.141592653L*sin(i/20))*31+31),fp);
  74.             fputc((cos(exp(cos(i/400)))*cos(3.1415926*sin(i/400))*31+31),fp);
  75.         }
  76.     fclose(fp);
  77. }
  78.